<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!-- This page is displayed as an popup when NeverSelectedSignature or SignatueSelectionAllUnpaid button of process payment request is clicked .It allows to select signatures
    and the selected signatures is saved to database and  then send to SsrsReportController for displaying the report-->
<script type="text/javascript">

	function clearDiv() {
			Popup.hide('neverSelectionPopUp');
			 $('#neverSelectionPopUp').html("");
		}
	$("input[type=checkbox]").click(function(){
		$("#errorMessageId").css('display', 'none');
	});


	
	function neverSelectedListId(){
		var payReqId="";

		<c:forEach items="${signatureReportBeanList}" var="signatureReportBean" varStatus="status">

			if($("input:checkbox[name='selection[${status.index}]']").is(':checked'))
		    	{
		    	   if(payReqId=="")
		    		   payReqId='${signatureReportBean.paymentRequest.id}';
		    	   else
		    		   payReqId +='|'+'${signatureReportBean.paymentRequest.id}';	    	   
			    	 }
	    </c:forEach>
	    if(payReqId=="")
	    {
	    	$("#errorMessageId").css('display', 'block').css('color','red').css('font-size',' 14px').css('text-align','center');
	    	
	    }else{
		    $("#concatePayreqId").val(payReqId);
		    $("#hiddentBtn").click();
		   
		    
		    window.open("<c:url value='/secure/signatureSelectionAllUnpaidPdf.do'> <c:param name='selectionType' value='${signatureReportBean.selectionType}'/><c:param name='userId' value='${signatureReportBean.userId}'/></c:url>").focus();
		    $("input:checkbox[name^='selection[']:checked").each(function() {
		    	this.checked = false;
		    });
// 		    clearDiv();
	    }
	}

	</script>
	

<div id="SignatureReportDiv" style="border: solid black; background-color:#ffffff;padding-bottom:10px; font-size:100%; text-align:left; ">
	<div  class="form_head">
        <c:choose>
        <c:when test="${signatureReportBean.selectionType=='NeverSelected'}">
		   <label style="font-size: 14px"><b>Never Selected Signature Report Form</b> </label>
		  </c:when>
		  <c:otherwise>
		    <label style="font-size: 14px"><b>Signature Selection All UnPaid Report Form</b> </label>		  
		  </c:otherwise>
		     </c:choose>
			<div class="floatR">
			  	<input type="image" src="<c:url value='/images/cross-button.jpg'/>" onClick="javascript:clearDiv()"/>				  
			</div>
			
	</div>
	<br/>
	
	<div class="form_body" style="padding-left:8px; " >
		<form:form name="signatureReport" id="signatureReport" target="_blank" action="saveNeverSelectedSignature.do" method="POST" modelAttribute="signatureReportBean">		   
		   <label id="errorMessageId" style="display:none;font-color:red;">YOu must select at least one payment request signature </label>
			<div  class="floatL">	
				<form:input type="text" id="selectionTypeId" path="selectionType" cssStyle="display:none;" />
				<form:input type="text" id="userId" path="userId" cssStyle="display:none;" />
			    <label style="font-weight:bold;">Signature Report Name: </label>
			    <form:input type="text" id="signatureReqNameId" path="signatureRequestFor" name="signatureRequestFor" />
			   	      
          	</div>
			<div  class="floatR" style="padding-right:16px; ">
			  
		              <a href="#" id="btnSignatureUpdating" class="blue_btn" onclick="" tabindex="-1">Update</a>
		              <a href="#" id="btnSignatureSelection" class="blue_btn" onclick="neverSelectedListId();" tabindex="-1">Display Report</a>			  
					   <sj:submit id="hiddentBtn" cssStyle="display:none;"></sj:submit>		
		   </div>
	        <br/><br/> 
          		<form:hidden id="concatePayreqId" path="concatePaymentReqId" />
         <div class="tableDIv" style=" max-height:400px; max-width:900px; overflow:scroll; "> 		
		  <table >
		  		  
			  <tbody id="signatureReportBody"  >	
				  
				  <c:forEach  items="${signatureReportBeanList}" var="signatureReport" varStatus="status">
					  <tr>
						  
						  <td><input type="checkbox" name="selection[${status.index}]"     value="${signatureReport.paymentRequest.id}" ></td>
						  <td> <fmt:formatDate value="${signatureReport.paymentRequest.creationDate}" pattern="MM-dd-yyyy" /> </td>
						  <td>${signatureReport.projectTitle}</td>
						  <td>${signatureReport.projectAcronym}</td>
						  <td colspan="2"> ${signatureReport.payeeName}</td>
						</tr>  
						<tr>  
						   <td colspan="2" >${signatureReport.paymentRequest.invoicenumber}</td>
						   <td><fmt:formatDate value="${signatureReport.paymentRequest.invoiceRequestDate}" pattern="MM-dd-yyyy" /></td>
						   
						    <td style="text-align: right;">${signatureReport.paymentRequest.amount}</td>
						    <td  style="border: solid #000 1px; font-style:oblique;" align="right">PMT ID:</td>
						    <td  style="border: solid #000 1px; font-style:oblique;" align="left">${signatureReport.paymentRequest.id}</td>
						     
					  </tr>
					  <tr>
					  <td colspan="6" style="border-bottom: solid 1px black;"/>
					  </tr>
					
				  </c:forEach>
			  </tbody>
		  </table>
		 </div>
		</form:form>
		
	</div>
</div>



